package com.hmall.common.client;

import com.hmall.common.config.FeignConfig;
import com.hmall.common.dto.Item;
import com.hmall.common.dto.PageDTO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;

// 在feign-api模块下resources创建包META-INF,新建名为spring.factories的file文件,设置自动装配
@FeignClient(value = "itemservice")
//@FeignClient(value = "itemservice",configuration = FeignConfig.class)
public interface ItemClient {

    /**
     * 分页查询商品(itemController中的)
     *
     * @param page
     * @param size
     * @return
     */
    @GetMapping("/item/list")
    PageDTO<Item> queryItemByPage(@RequestParam("page") Integer page,
                                         @RequestParam("size") Integer size);

    /**
     * 根据id查询商品(itemController中的)
     * @param id
     * @return
     */
    @GetMapping("/item/{id}")
    Item queryById(@PathVariable("id") Long id);

    /**
     * 扣减库存接口
     * @param itemId
     * @param num
     */
    @PutMapping("/item/stock{itemId}/{num}")
    void upudateStock(@PathVariable("itemId") Long itemId,
                      @PathVariable("num") Integer num);
}
